package dymnd.ui;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class ToastPanel extends JPanel implements Runnable{
	
	String mesg;
	Color color;
	
	long startTime;
	
	int time;
	
	public static final int HASTE_TIME = 2000;
	public static final int LAZY_NOTIFICATION = 3000;
	
	
	public ToastPanel(String s, Color c, int time)	{
		mesg = s;
		color = c;
		this.time = time;
	}
	
	double durationPercent;
	Font font = new Font("Arial", Font.BOLD, 20);
	int rgb = 255;
	
	public void paintComponent(Graphics arg0)	{
		Graphics2D g = (Graphics2D) arg0;
		
		g.setComposite(AlphaComposite.Src);
		
		g.setColor(new Color(rgb, rgb, rgb, rgb));
		g.setFont(font);
		g.drawString(mesg, getWidth()/2, getHeight()/2);
		
		System.out.println("repainted");
		//getParent().repaint();
	}
	
	public void run()	{
		System.out.println("wee");
		startTime = System.currentTimeMillis();
		while(System.currentTimeMillis() - startTime <= time)	{
			repaint();
			
			rgb = (int)(rgb*(((double)time - (double)(System.currentTimeMillis() - startTime))/(double)startTime));
			
			//System.out.println("repainted");
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				
				e.printStackTrace();
			}
		}
		
	
	}
	
}
